<?php

/*
 * $data :
 *		array(
 *			"title" => "mytitle",
 *			"elements" => new spWhatever
 *		)
 */
 
class spElementLayoutVertical extends spDiv
{
	private $data;

	public function __construct( $data=array() )
	{
		$this->data = $data;
		parent::__construct();
		
		foreach ( $data["elements"] as $element )
		{
			if ( isset($element["show"]) && $element["show"]==false )
				continue;

			$show_field = isset($element["show_field"])?$element["show_field"]:true;

			$fieldset = null;
			
			if ( $show_field )
			{
				$fieldset = new spFieldSet;
				$fieldset->addStyle( "background-color", "#FFDEAD" );
				$fieldset->addStyle( "border", "1px solid #cccccc" );
				$fieldset->addStyle( "padding", "5px" );
				parent::addChild( $fieldset );
				
				if ( isset( $element["title"] ) )
				{
					$legend = new spLegend;
					$h2 = new spHeading;
					$h2->setLevel( 2 );
					$legend->addChild( $h2 );
					$h2->setContent( $element["title"] );
					$fieldset->addChild( $legend );
				}
			}

			if ( isset( $element["element"] ) )
			{
				if ( $fieldset )
					$fieldset->addChild( $element["element"] );
				else
					parent::addChild( $element["element"] );
			}

			if ( $show_field )
			{
				if ( isset( $element["subtext"] ) )
				{
					$fieldset->addChild( new spBreak );
					$i = new spItalic;
					$i->setContent( $element["subtext"] );
					$fieldset->addChild( $i );
				}
			}
		}
	}
}

?>